package com.magicsoft.share.adapter.exchange;

import android.support.annotation.LayoutRes;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.magicsoft.share.R;
import com.magicsoft.share.bean.exchange.GoodsSubmit;
import com.magicsoft.share.bean.exchange.SubmitOrder;

import java.util.List;

/**
 * Created by lyf on 2017/11/9/009.
 */

public class SettlementAdapter extends BaseQuickAdapter<GoodsSubmit, BaseViewHolder> {


    public SettlementAdapter(@LayoutRes int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, GoodsSubmit item) {
        helper.setText(R.id.tv_name, item.getGoodsName())
                .setText(R.id.tv_price, item.getPrice() + "")
                .setText(R.id.tv_num, "x" + item.getGoodsNum());
        ImageView imageView = helper.getView(R.id.imageView);

        Glide.with(mContext).load(item.getGoodsImg()).into(imageView);
        helper.addOnClickListener(R.id.delete);
        helper.addOnClickListener(R.id.checkbox);

        if (item.getCheckStock() == 1) {
            helper.setVisible(R.id.tv_no_spec, false);
        } else {
            helper.setVisible(R.id.tv_no_spec, true);
        }
    }


    public void refreshData(SubmitOrder submitOrder) {
        List<SubmitOrder.ListBean> list = submitOrder.getList();
        for (int i = 0; i < list.size(); i++) {
            SubmitOrder.ListBean listBean = list.get(i);
            long goodsId = listBean.getGoodsId();
            if (listBean.getStock() == 0) {
                for (int j = 0; j < mData.size(); j++) {
                    if (mData.get(j).getGoodsId() == goodsId) {
                        mData.get(j).setCheckStock(0);
                        this.notifyItemChanged(j);
                    }
                }
            }
        }

    }
}
